<?php 
class CBlogController extends CController{

	protected $m_objPage;
	
	function __construct() {
		parent::__construct();
		return true;
	}
	
	function initialize() {
		parent::initialize();
		return true;
	}
	
	function execute() {
		
		switch( $this->m_strAction ) {
			case 'view_blogs':	
				$this->handleViewBlog();
				break;
				
			case 'view_blog_detail':
				$this->handleViewBlogDetail();
				break;
				
			
			default:
				$this->handleViewBlog();
				
		}
	}

	/*************************************
	********** HANDLE FUNCTIONS **********
	*************************************/
	
	function handleViewBlog() {
		
		$this->m_arrobjBlog = CBlogs::fetchBlogs( $this->m_objDatabase );
		$this->m_arrobjUser = CUsers::fetchUsers( $this->m_objDatabase );
		$this->m_arrobjComment = CComments::fetchComments( $this->m_objDatabase );
		
		$this->displayViewBlog();
	}
	
	function handleViewBlogDetail() {
		
		$this->m_objBlog = CBlogs::fetchBlogById( $_REQUEST['id'], $this->m_objDatabase );
		$this->m_objUser = CUsers::fetchUserById( $this->m_objBlog->getCreatedBy(), $this->m_objDatabase );
		$this->m_arrobjComment = CComments::fetchCommentsByBlogId( $this->m_objBlog->getId(), $this->m_objDatabase );
	
		$this->displayViewBlogDetail();
	}

	/**************************************
	********** DISPLAY FUNCTIONS **********
	**************************************/	
		
	function displayViewBlog() {
		parent::display();

		$this->m_objSmarty->assign_by_ref( 'blogs', $this->m_arrobjBlog );
		$this->m_objSmarty->assign_by_ref( 'users', $this->m_arrobjUser );
		$this->m_objSmarty->assign_by_ref( 'comments', $this->m_arrobjComment );
	
				
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/blog/view_blog.tpl');

	}
	
	function displayViewBlogDetail() {
		parent::display();
	
		$this->m_objSmarty->assign_by_ref( 'blog', $this->m_objBlog );
		$this->m_objSmarty->assign_by_ref( 'user', $this->m_objUser );
		$this->m_objSmarty->assign_by_ref( 'comments', $this->m_arrobjComment );
	
	
		$this->m_objSmarty->display( TEMPLATE_DIR_PATH . '/blog/view_blog_detail.tpl');
	
	}

}
?>